package com.online.college.rest.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.online.college.common.web.JsonView;
import com.online.college.core.course.domain.Course;
import com.online.college.rest.business.ICourseBusiness;

@Controller
@RequestMapping("course")
public class PortalCourseController {

	@Autowired
	private ICourseBusiness courseBusiness;
	
	@RequestMapping(value="getCourse")
	@ResponseBody
	public String getCourse(HttpServletRequest request){
		Map<String,List<Course>> returnMap = new HashMap<String,List<Course>>();
		try{
			returnMap = courseBusiness.getCourse();
		}catch(Exception e){
			JsonView.render("0");
		}
		return request.getParameter("callback")+"("+JsonView.render(returnMap)+")";
	}
}
